<template>
  <view class="cart-container">
    <!-- 收获地址 -->
    <my-address></my-address>
    <!-- 购物车标题 -->
    <view class="cart-title">
      <uni-icons type="shop" size="20" color="red"></uni-icons>
      <text class="cart-name">购物车</text>
    </view>
    <!-- 商品列表 -->
    <uni-swipe-action>
      <block v-for="(goods,i) in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods.goods_id)">
          <my-goods :goods="goods" :show-radio="true" :show-count="false" :show-number="true"
            @radioChanged="radioChangeHandler" @numChanged="numChangeHandler"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算区域 -->
    <my-settle></my-settle>
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#C00000'
          }
        }]
      };
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsById']),
      radioChangeHandler(e) {
        // 更新商品状态
        this.updateGoodsState(e)
      },
      numChangeHandler(e) {
        // 更新商品数量
        this.updateGoodsCount(e)
      },
      swipeActionClickHandler(goods_id) {
        // 删除商品
        this.removeGoodsById(goods_id)
      }
    }
  }
</script>

<style lang="scss">
  .cart-container {
    padding-bottom: 50px;
  }

  .cart-title {
    height: 40px;
    padding-left: 5px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #aa00ff;

    .cart-name {
      font-size: 16px;
      margin-left: 10px;
    }
  }
</style>